package administrator;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import java.sql.*;

public class TestSchedule {

	public JFrame frame;
	private JTable table;

	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestSchedule window = new TestSchedule();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	
	public TestSchedule() {
		initialize();
	}

	
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(350, 150, 695, 440);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JPanel panel1 = new JPanel();
		panel1.setBackground(new Color(255, 215, 0));
		panel1.setBounds(10, 77, 659, 274);
		frame.getContentPane().add(panel1);
		panel1.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 0, 659, 274);
		panel1.add(scrollPane);
		
		table = new JTable();
		table.setModel(new javax.swing.table.DefaultTableModel(
	            new Object [][] {

	            },
	            new String [] {
	            		"Centre Code", "Test Centre" , "Date",  "No. of Students"
	            }
	        ));
	        scrollPane.setViewportView(table);
		
		JPanel panel = new JPanel();
		panel.setBackground(new Color(255, 69, 0));
		panel.setBounds(10, 24, 659, 42);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel TestSchedule = new JLabel("Test Schedule");
		TestSchedule.setFont(new Font("Tahoma", Font.BOLD, 15));
		TestSchedule.setHorizontalAlignment(SwingConstants.CENTER);
		TestSchedule.setBounds(10, 0, 639, 42);
		panel.add(TestSchedule);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });
		btnBack.setBounds(305, 362, 89, 23);
		frame.getContentPane().add(btnBack);
	}
	
	public void display()
	{
		
		DefaultTableModel model = (DefaultTableModel) table.getModel();
        while(model.getRowCount()>0)
        {
            model.removeRow(0);
        }
        try
        {
            Class.forName("java.sql.Driver");
            
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3307/oats","root","anupam24");
            Statement stmt = con.createStatement();

            String sql="select * from test_scedule ";
            
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next())
            {
                int code = rs.getInt(1);
                String centre = rs.getString(2);
                String date = rs.getString(3);
                int n = rs.getInt(4);
                           
                model.addRow(new Object[] {code,centre,date,n});

            }
            rs.close();
            stmt.close();
            con.close();
        }
        catch(Exception e)
        {
            System.out.println("Error is : "+e.getMessage());
        }
	}
	private void btnBackActionPerformed(java.awt.event.ActionEvent evt)
	{
		Admn_Menu am = new Admn_Menu();
		am.frame.setVisible(true);
		this.frame.setVisible(false);
	}
	
}
